package com.cskaoyan._10exception._02handle;

/**
 * @author Macro_Ray
 * @since 2024/3/19 10:37
 */
// try catch
// 1. try块：可能出现异常的代码
// 2. catch块：捕获异常的代码
//      catch里面一定是抓指定对应的异常，或者是这个异常的父类，否则不会执行
public class Try {
    public static void main(String[] args) {
        System.out.println("main start");
        test1();
        System.out.println("main end");

    }

    private static void test1() {
        System.out.println("test1 start");
        test2();
        System.out.println("test1 end");
    }

    private static void test2() {
        System.out.println("test2 start");
        try {
            String s = null;
            s.length();
        } catch (NullPointerException e) {
            System.out.println("出现了空指针");
        }
        System.out.println("test2 end");
    }
}
